package tuan.score;

import java.util.Map;

import org.w3c.dom.Node;

public class EqualParentTagScore extends NodeScore {
	Map<String, Double> scoreRule;

	public EqualParentTagScore(Map<String, Double> scoreRule) throws Exception {
		if (scoreRule == null) {
			throw new Exception("null arguments");
		}
		this.scoreRule = scoreRule;
	}

	@Override
	protected double getScore(Node node) {
		double defaultScore = scoreRule.containsKey("") ? scoreRule.get("") : 0.0;
		node = node.getParentNode();
		if (node != null && scoreRule.containsKey(node)) {
			return scoreRule.get(node.getNodeName());
		} else {
			return defaultScore;
		}
	}

}
